package com.sailing.xjpb.dict.config;

import com.sailing.xjpb.dict.service.DictionaryService;
import com.sailing.xjpb.dict.service.impl.DictionaryServiceImpl;
import com.sailing.xjpb.dict.translate.handler.DictTranslateHandler;
import com.sailing.xjpb.dict.translate.handler.EnumTranslateHandler;
import com.sailing.xjpb.orm.intercepter.CrudRepositoryBeanPostProcessor;
import com.sailing.xjpb.orm.intercepter.CrudRepositoryOperatorHandler;
import com.sailing.xjpb.orm.intercepter.impl.DefaultCurdRepositoryOperatorHandler;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 枚举服务自动注入类
 *
 * @author YaoWei
 */
@Configuration
public class DictAutoConfiguration {

    @Bean
    public DictionaryService dictionaryService() {
        return new DictionaryServiceImpl();
    }

    @Bean
    public DictTranslateHandler dictTranslateHandler() {
        return new DictTranslateHandler();
    }

    @Bean
    public EnumTranslateHandler enumTranslateHandler() {
        return new EnumTranslateHandler();
    }

    @ConditionalOnMissingBean(CrudRepositoryBeanPostProcessor.class)
    @Bean
    public CrudRepositoryBeanPostProcessor crudRepositoryBeanPostProcessor() {
        return new CrudRepositoryBeanPostProcessor();
    }

    /**
     * add by YaoWei since 2023-03-14
     *
     * @return 操作人记录器
     */
    @ConditionalOnMissingBean(CrudRepositoryOperatorHandler.class)
    @Bean
    public CrudRepositoryOperatorHandler crudRepositoryOperatorHandler() {
        return new DefaultCurdRepositoryOperatorHandler();
    }

}
